package com.ld.poetry.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.entity.ProhibitedWords;
import com.ld.poetry.service.ProhibitedWordsService;
import com.ld.poetry.utils.CommonConst;
import com.ld.poetry.vo.ProhibitedWordsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 违禁词管理
 * @Author: 杨旭
 * @PackageName: poetize
 * @Package: com.ld.poetry.controller
 * @Date: 2023/7/4 12:58
 * @explain:
 */
@RestController
@RequestMapping("/prohibitedWords")
public class ProhibitedWordsController {


    @Autowired
    ProhibitedWordsService prohibitedWordsService;

    /**
     * 增加违禁词
     *
     * @return
     */
    @RequestMapping("/add")
    public PoetryResult addProhibitedWords(@RequestBody ProhibitedWords prohibitedWords) {
        if (StringUtils.hasText(prohibitedWords.getWord())) {
            return prohibitedWordsService.add(prohibitedWords);
        }
        return PoetryResult.success("添加失败");
    }

    /**
     * 删除违禁词
     *
     * @return
     */
    @RequestMapping("/delete")
    public PoetryResult delProhibitedWords(String id) {
        prohibitedWordsService.removeById(id);
        return PoetryResult.success();
    }

    /**
     * 更新违禁词
     *
     * @return
     */
    @RequestMapping("/update")
    public PoetryResult updateProhibitedWords(@RequestBody ProhibitedWords prohibitedWords){
        prohibitedWordsService.updateById(prohibitedWords);
        return PoetryResult.success();
    }

    /**
     * 查询违禁词
     *
     * @return
     */
    @RequestMapping("/list")
    public PoetryResult<Page> showProhibitedWords(@RequestBody ProhibitedWordsVO prohibitedWordsVO) {
        return prohibitedWordsService.listProWord(prohibitedWordsVO);
    }

//    @RequestMapping("/synchronous")
//    public PoetryResult synchronous() {
//        List<ProhibitedWords> list = new ArrayList<>();
//
//        for (String s : CommonConst.WEIJINCI) {
//            ProhibitedWords prohibitedWords = new ProhibitedWords();
//            prohibitedWords.setWord(s);
//            list.add(prohibitedWords);
//        }
//
//        prohibitedWordsService.saveBatch(list);
//        return PoetryResult.success();
//    }
}
